<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Scales an image</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="imagick.resetimagepage.html">« Imagick::resetImagePage</a></li>
      <li style="float: right;"><a href="imagick.rollimage.html">Imagick::rollImage »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.imagick.html">Imagick</a></li>
    <li>Scales an image</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="imagick.resizeimage" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Imagick::resizeImage</h1>
  <p class="verinfo">(PECL imagick 2, PECL imagick 3)</p><p class="refpurpose"><span class="refname">Imagick::resizeImage</span> &mdash; <span class="dc-title">Scales an image</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-imagick.resizeimage-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Imagick::resizeImage</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$columns</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$rows</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$filter</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">float</span> <code class="parameter">$blur</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$bestfit</code><span class="initializer"> = <strong><code>false</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$legacy</code><span class="initializer"> = <strong><code>false</code></strong></span></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Scales an image to the desired dimensions with a
   <a href="imagick.constants.html#imagick.constants.filters" class="link">filter</a>.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
<span class="simpara">
 参数 <code class="parameter">bestfit</code> 的特性在 Imagick 3.0.0 中已改变。在此版本以前，当目标尺寸设为
 400x400 时，原尺寸为 200x150 的图像将不会被改变。自 Imagick 3.0.0
 起，源图像将会被放大到 400x300 因为这将更好的适合目标尺寸。当使用参数
 <code class="parameter">bestfit</code> 时，必须同时给出宽度和高度。
</span>
</p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-imagick.resizeimage-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">columns</code></dt>

     <dd>

      <p class="para">
       Width of the image
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">rows</code></dt>

     <dd>

      <p class="para">
       Height of the image
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">filter</code></dt>

     <dd>

      <p class="para">
       Refer to the list of <a href="imagick.constants.html#imagick.constants.filters" class="link">filter constants</a>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">blur</code></dt>

     <dd>

      <p class="para">
       The blur factor where &gt; 1 is blurry, &lt; 1 is sharp.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">bestfit</code></dt>

     <dd>

      <p class="para">
       Optional fit parameter.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-imagick.resizeimage-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-imagick.resizeimage-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL imagick 2.1.0</td>
       <td>
       Added optional fit parameter. This method now supports proportional scaling.
       Pass zero as either parameter for proportional scaling.  
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>




 <div class="refsect1 examples" id="refsect1-imagick.resizeimage-examples">
  <h3 class="title">范例</h3>
  <p class="para">
    <div class="example" id="example-2846">
      <p><strong>示例 #1  <span class="function"><strong>Imagick::resizeImage()</strong></span></strong></p>
      <div class="example-contents">
      <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">resizeImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$imagePath</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$filterType</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$blur</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bestFit</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$cropZoom</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//The&nbsp;blur&nbsp;factor&nbsp;where&nbsp;&gt;&nbsp;1&nbsp;is&nbsp;blurry,&nbsp;&lt;&nbsp;1&nbsp;is&nbsp;sharp.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$imagick&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">(</span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #0000BB">$imagePath</span><span style="color: #007700">));<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">resizeImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$filterType</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$blur</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bestFit</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$cropWidth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageWidth</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$cropHeight&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageHeight</span><span style="color: #007700">();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$cropZoom</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$newWidth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$cropWidth&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$newHeight&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$cropHeight&nbsp;</span><span style="color: #007700">/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">cropimage</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$newWidth</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$newHeight</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="color: #0000BB">$cropWidth&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">$newWidth</span><span style="color: #007700">)&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="color: #0000BB">$cropHeight&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">$newHeight</span><span style="color: #007700">)&nbsp;/&nbsp;</span><span style="color: #0000BB">2<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">scaleimage</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageWidth</span><span style="color: #007700">()&nbsp;*&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageHeight</span><span style="color: #007700">()&nbsp;*&nbsp;</span><span style="color: #0000BB">4<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type:&nbsp;image/jpg"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageBlob</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

    </div>
  </p>
 </div>


</div></div></div></body></html>